TARGET		:= lib$(notdir $(CURDIR)).so
CUR_HEADER  := $(notdir $(CURDIR)).h
SOURCE		:= $(wildcard *.c)  
OBJS		:= $(patsubst %.c, %.o, $(SOURCE))
HEADER		:= $(wildcard *.h)
AR			:= arm-linux-ar
AR_FLAGS	:= rcs
TEST		:= app
APP_PATH	:= /home/ywt/share/project/bin
TEST_DIR    := test

ifndef ARG
CCG			:= arm-linux-gcc
LIB_PATH	:= ../../../lib/reader
INCLUDE_DIR := ../../../include/reader
endif


C_FLAGS 	+=  -Wall -Os
C_FLAGS     += -fPIC -shared

all:$(TARGET)
ifeq  ($(TEST_DIR), $(wildcard $(TEST_DIR)))
	$(CCG) -o $(TEST) test/reader_app.c -lpthread -L./ -lreader
endif

$(TARGET):$(SOURCE)$(HEADER)
	$(CCG) $(C_FLAGS) $(SOURCE) -o $(TARGET)


.PHONY: clean install
clean:
	$(RM) *.o $(TARGET) $(TEST)

install:
	@if test ! -d $(APP_PATH);then \
		mkdir $(APP_PATH); \
		echo "mkdir $(APP_PATH)"; \
	else \
		cp $(TEST) $(TARGET) $(APP_PATH); \
		echo "cp $(TEST) $(TARGET) $(APP_PATH)"; \
	fi
	@if test ! -d $(LIB_PATH);then \
		mkdir $(LIB_PATH); \
		echo "mkdir $(LIB_PATH)"; \
	else \
		cp $(TARGET) $(LIB_PATH); \
		echo "cp $(LIB_PATH) $(LIB_PATH)"; \
	fi
	@if test ! -d $(INCLUDE_DIR);then \
		mkdir $(INCLUDE_DIR); \
		echo "mkdir $(INCLUDE_DIR)"; \
	else \
		cp $(CUR_HEADER) $(INCLUDE_DIR); \
		echo "cp $(CUR_HEADER) $(INCLUDE_DIR)"; \
	fi


